#ifndef __SHARERAM_CAMERA
#define __SHARERAM_CAMERA

#include <stdio.h>
#include <string>
#include <unistd.h>

#include <opencv2/opencv.hpp>

#include <iostream>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <stdio.h>

#define SHMNAME "shm_decoder_front"
#define SHMNAME1 "shm_decoder_middle"
#define SHMNAME2 "shm_decoder_back"
#define SHMNAME3 "shm_decoder_plate"
#define SHMNAME4 "shm_decoder_front1"
#define SHMNAME5 "shm_decoder_middle1"
#define SHMNAME6 "shm_decoder_back1"
#define SHMNAME7 "shm_decoder_plate1"
#define OPEN_FLAG O_RDWR|O_CREAT
#define OPEN_MODE 00777

typedef struct 
{
    volatile bool rLock;
    volatile bool wLock;
    volatile unsigned int counter;
    unsigned char data[1920*1080*3];
}MatBuf;

class Camera
{
public:
    Camera();
    virtual ~Camera();

    bool initShm(char *shmName);
    bool getNewMat(cv::Mat &mat);
    bool getNewMat(cv::Mat &mat, unsigned int &index);
    bool getMatByIndex(cv::Mat &mat, unsigned int index);

private:

    void* shareMatAddr = nullptr;
    unsigned int historyCounter = 0;
};

#endif
